package com.opencloud.iot.provider.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opencloud.common.model.PageParams;
import com.opencloud.common.model.ResultBody;
import com.opencloud.iot.client.model.entity.IotRecorders;
import com.opencloud.iot.provider.service.IotRecordersService;
import com.opencloud.iot.provider.service.feign.YwtRemoteService;
import com.opencloud.ywt.client.model.entity.BhyfAngleRecord;
import com.opencloud.ywt.client.model.entity.BhyfBflAngle;
import com.opencloud.ywt.client.model.entity.BhyfBflAngleBeacon;
import com.opencloud.ywt.client.model.entity.BhyfStudent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 物联设备（手环）信息
 * @author yeyong
 */
@RestController
@Api(value = "物联网设备", tags = "物联网设备（手环）进出记录查看")
public class IotRecordersController {
    @Autowired
    private IotRecordersService iotRecordersService;
    @Autowired
    private YwtRemoteService ywtRemoteService;

    /**
     * 获取手表状态分页信息
     * @param map
     * @param StartTime
     * @param EndTime
     * @return
     */
    @ApiOperation(value = "获取手表进出记录分页信息", notes = "获取手表进出记录分页信息")
    @GetMapping("/records/infos")
    public ResultBody<IPage<IotRecorders>> getWatchInfoListPage(@RequestParam(required = false) Map map,@RequestParam(required = false)Long StartTime,@RequestParam(required = false)Long EndTime){
        if(ObjectUtils.isEmpty(StartTime))StartTime=new Date(1546272000*1000).getTime()/1000;
        if(ObjectUtils.isEmpty(EndTime))EndTime=new Date().getTime()/1000;
        return ResultBody.ok().data(iotRecordersService.findListPage(new PageParams(map),StartTime,EndTime));
    }

    /**
     * API-获取手表进出记录
     * @param StartTime
     * @param EndTime
     * @return
     */
    @ApiOperation(value = "API-获取手表进出记录", notes = "API-获取手表进出记录")
    @GetMapping("/api_records/list")
    public List<IotRecorders> getWatchInfoList(@RequestParam(required = false)Long StartTime, @RequestParam(required = false)Long EndTime,@RequestParam(required = false)String Watchs){
        if(ObjectUtils.isEmpty(StartTime))StartTime=new Date(1546272000*1000).getTime()/1000;
        if(ObjectUtils.isEmpty(EndTime))EndTime=new Date().getTime()/1000;
        return iotRecordersService.findList(StartTime,EndTime,Watchs);
    }
}
